package com.panshi.controller;

import com.panshi.api.SysMenuApi;
import com.panshi.vo.R;
import com.panshi.vo.SysMenuVO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    private SysMenuApi sysMenuApi;

    @RequiresPermissions("menu:list:*")
    @GetMapping("/treeTableMenu")
    public Map<String,Object> treeTableMenu(){
        return sysMenuApi.treeTableMenu();
    }

    @RequiresPermissions("menu:add:*")
    @PostMapping
    public R addMenu(@RequestBody SysMenuVO sysMenuVO){
        return sysMenuApi.addSysMenu(sysMenuVO);
    }

    @RequiresPermissions("menu:edit:*")
    @PutMapping
    public R editMenu(@RequestBody SysMenuVO sysMenuVO){
        R r = sysMenuApi.editSysMenu(sysMenuVO);
        System.out.println(r);
        return r;
    }

    @RequiresPermissions("menu:del:*")
    @DeleteMapping("/{id}")
    public R delMenu(@PathVariable("id")Integer id){
        return sysMenuApi.delSysMenu(id);
    }


    //下拉框,新增展示
    @GetMapping("/menuXmSelectList")
    public R menuSelectList(){
        return sysMenuApi.xmSelect();
    }

    //下拉框,修改回显
    @GetMapping("/menuXmSelectListByRoleId/{id}")
    public R menuSelectListByRoleId(@PathVariable("id")Integer id){
        return sysMenuApi.getRoleXmSelect(id);
    }

}
